class GenericModelService:
    def __init__(self, model):
        self.model = model

    def create_object(self, **kwargs):
        """
        创建新对象
        :param kwargs: 对象属性键值对
        :return: 创建成功返回新对象，失败返回 None
        """
        try:
            obj = self.model.objects.create(**kwargs)
            return obj
        except Exception as e:
            print(f"创建对象失败: {e}")
            return None

    def get_all_objects(self):
        """
        获取所有对象
        :return: 对象查询集
        """
        return self.model.objects.all()

    def get_object_by_id(self, obj_id):
        """
        根据 ID 获取单个对象
        :param obj_id: 对象 ID
        :return: 找到返回对象，未找到返回 None
        """
        try:
            return self.model.objects.get(id=obj_id)
        except self.model.DoesNotExist:
            return None

    def get_objects_by_filter(self, **kwargs):
        """
        根据条件过滤对象
        :param kwargs: 过滤条件键值对
        :return: 符合条件的对象查询集
        """
        return self.model.objects.filter(**kwargs)

    def update_object(self, obj_id, **kwargs):
        """
        更新对象属性
        :param obj_id: 对象 ID
        :param kwargs: 要更新的属性键值对
        :return: 更新成功返回更新后的对象，未找到对象返回 None
        """
        obj = self.get_object_by_id(obj_id)
        if obj:
            for key, value in kwargs.items():
                setattr(obj, key, value)
            obj.save()
            return obj
        return None

    def delete_object(self, obj_id):
        """
        删除对象
        :param obj_id: 对象 ID
        :return: 删除成功返回 True，未找到对象返回 False
        """
        obj = self.get_object_by_id(obj_id)
        if obj:
            obj.delete()
            return True
        return False